package com.mlog.njyjy.ndop.monitor.collector.task;

import com.mlog.njyjy.ndop.monitor.collector.dao.TaskRepository;
import com.mlog.njyjy.ndop.monitor.common.domain.Task;
import com.mlog.njyjy.ndop.monitor.common.support.Constants;
import lombok.extern.slf4j.Slf4j;

/**
 * 告警线程
 *
 * @author zyz
 * @version v1.0, 2020/07/29
 */
@Slf4j
public class AlertRunnable implements Runnable {

    private int taskId;

    private TaskRepository taskRepository;

    public AlertRunnable(int taskId, TaskRepository taskRepository) {
        this.taskId = taskId;
        this.taskRepository = taskRepository;
    }

    @Override
    public void run() {
        Task task = taskRepository.findOne(taskId);
        if (task == null) {
            log.error("监控任务 {} 不存在...", taskId);
        } else {
            if (Constants.PRODUCT_STATUS_HAVE_REACHED.equalsIgnoreCase(task.getProductStatus())) {
                log.warn("产品 {} 已到达....", task.getProductName().concat(".").concat(task.getPdtFileExt()));
            } else {
                log.warn("产品 {} 未到达或到达错误....", task.getProductName().concat(".").concat(task.getPdtFileExt()));
                //TODO:告警
            }

        }

    }
}
